package zuoye;

public class SeqStack <T>{
   private  int max=10;
   private Object[] arr = (T []) new Object[max];
   private  int len = 0;


    //进栈
    public void push(T data){
        if(len>=max){
            System.out.println("溢满");
            return;
        }
      arr[len ] =data;
      len++;
    }
    //获取数组个数
    public int getCount(){
        return len;
    }

    //出栈
    public void pop(){
        if(len==0){
            System.out.println("此表为空");
            return;
        }

        len--;

    }

    //显示最顶层
    public Object top(){
        return arr[len-1];
    }

    //逆序
    public void reverse(){

    for(int i=0;i<len/2;i++){
        Object team = arr[i];
        arr[i]=arr[len-1-i];
        arr[len-1-i] = team;
    }
    }
    //打印
    public void display(){
        if(len==0){
            System.out.println("此表为空");
            return;
        }

        for(int i = 0; i<len; i++){
            System.out.print(arr[i]+"  ");
        }
        System.out.println();
    }

    public boolean isEmpty() {
        return len==0;
    }
}
